package com.example.zx.keysoapapplication;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by ZX on 2016/4/17.
 */
public class MyAdapter extends BaseAdapter {
    private List<Food> foods;
    private LayoutInflater inflater;
    public MyAdapter(List<Food> foods,LayoutInflater inflater){
        this.foods=foods;
        this.inflater=inflater;
    }
    @Override
    public int getCount() {
        return foods.size();
    }

    @Override
    public Object getItem(int position) {
        return foods.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    //渲染
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView=inflater.inflate(R.layout.ppo,null);
        TextView title=(TextView)convertView.findViewById(R.id.tit);
        TextView con=(TextView)convertView.findViewById(R.id.con);
        ImageView ima=(ImageView)convertView.findViewById(R.id.pic);
        title.setText(foods.get(position).getTitle());
        con.setText(foods.get(position).getContext());
        ima.setImageResource(foods.get(position).getPic());
        ima.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("zx",foods.get(position).getTitle().toString()+"");
            }
        });
        return convertView;
    }
}
